package com.damieoa.damieoa.controller;

import com.damieoa.damieoa.pojo.Staff;
import com.damieoa.damieoa.pojo.Station;
import com.damieoa.damieoa.service.StaffService;
import com.damieoa.damieoa.vo.PageUtils;
import com.damieoa.damieoa.vo.SysResult;
import com.github.pagehelper.ISelect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@Transactional
@RequestMapping("/staff")
public class Staffcontroller {

    @Autowired
    private StaffService staffService;

    //添加员工并添加该员工的状态信息
    @PostMapping("/add")
    public SysResult addStaff(@RequestBody Staff staff){
        staffService.addStaff(staff);
        return SysResult.success();
    }

    //员工信息查询
    @GetMapping("/query")
    public SysResult queryStaff(Staff staff){
        return SysResult.success(PageUtils.startPage().doSelectPageInfo(new ISelect() {
            @Override
            public void doSelect() {
                staffService.queryStaff(staff);
            }
        }));
    }

    //员工信息删除
    @DeleteMapping("/delete")
    public SysResult deleteStaff(Staff staff){
        staffService.deleteStaff(staff);
        return SysResult.success();
    }

    //员工详细信息查询
    @GetMapping("/particular_query")
    public SysResult particularQueryStaff(Staff staff){
        return SysResult.success(staffService.particularQueryStaff(staff));
    }

    //员工详细信息修改
    @PutMapping("/updateStaff")
    public SysResult updateStaff(@RequestBody Staff staff){
        staffService.updateStaff(staff);
        return SysResult.success();
    }

}
